﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace 多窗口案例
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            InputWindow inputWin = new InputWindow();
            bool? b = inputWin.ShowDialog();
            if (b == null)
            {
                MessageBox.Show("没设置？");
            }
            else if (b == true)
            {
                MessageBox.Show("确定:"+inputWin.InputValue);
            }
            else
            {
                MessageBox.Show("取消");
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("ffff","提示",MessageBoxButton.OK);

            //Show返回值得知点击的按钮，
            //MessageBoxResult r1=
            //    MessageBox.Show("确定还是取消？", "提示", MessageBoxButton.OKCancel);
            //if (r1 == MessageBoxResult.OK)
            //{
            //    MessageBox.Show("ok啦！");
            //}
            //else if(r1== MessageBoxResult.Cancel)
            //{
            //    MessageBox.Show("取消了");
            //}

            //MessageBoxResult r2 =
            //    MessageBox.Show("真的要删除？", "警告", MessageBoxButton.YesNo);
            //if (r2 == MessageBoxResult.Yes)
            //{
            //    MessageBox.Show("删的干净！");
            //}
            //else if (r2 == MessageBoxResult.No)
            //{
            //    MessageBox.Show("多亏没删！！");
            //}
            MessageBox.Show("真的要删除？", "警告", MessageBoxButton.YesNoCancel);

            //实现一个含有：确定、取消、重试三个按钮的对话框。调用者可以设置窗口标题和窗口显示的文字，调用者可以得知按的是哪个按钮。
            //MyWindow win = new .....;
            //win.Title="哈哈";
            //win.Message="真的要是？";
            ////1:    bool? b =  win.ShowDialog();
            ////2:    win.ShowDialog();
            ////2:    枚举类型  r = win.Result;
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            //OpenFileDialog ofd = new OpenFileDialog();
            //ofd.Filter = "文本文件|*.txt|PNG图片|*.png|视频|*.avi|所有文件|*.*";
            //if (ofd.ShowDialog() == true)
            //{         
            //    string file = ofd.FileName;//打开的文件名
            //    MessageBox.Show("打开文件" + file);
            //}
            //else
            //{
            //    MessageBox.Show("取消了");
            //}

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "文本文件|*.txt|word文档|*.doc";
            if (sfd.ShowDialog() == true)
            {
                //会自动加后缀扩展名
                MessageBox.Show(sfd.FileName);
            }
        }

        private void btnChoosePic_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "JPEG图片|*.jpg|PNG图片|*.png|BMP图片|*.bmp";
            if (ofd.ShowDialog() == true)
            {
                string picFileName = ofd.FileName;
                image1.Source = new BitmapImage(new Uri(picFileName));
            }
        }
    }
}
